import 'package:flutter/material.dart';
import 'package:kasax/commons/commons.dart';

import 'detail_listitem_test.dart';

enum BuildStyle { DEFAULT, DYNAMIC, BUILDER, SPERATOR }

class ListItem {
  final String text;
  bool isHeader;

  ListItem(this.text, {this.isHeader = false});
}

class ListViewItemEventDemo3 extends StatefulWidget {
  const ListViewItemEventDemo3({Key? key}) : super(key: key);

  @override
  _ListViewItemEventDemo3State createState() => _ListViewItemEventDemo3State();
}

class _ListViewItemEventDemo3State extends State<ListViewItemEventDemo3> {
  BuildStyle _style = BuildStyle.DEFAULT;
  List<ListItem> list = <ListItem>[
    ListItem("Create a new organization for free", isHeader: true),
    ListItem(
        "Better code starts with pull requests—conversations around your code where you can experiment, squash bugs, and build new features."),
    ListItem(
        "Code review is built in. Pull requests cover the entire review flow: propose changes, browse code, ask for input, make a suggestion, and sign off in one place."),
    ListItem(
        "Know when your pull request is ready to merge when everything’s green. Reviews approved? Check. Tests passing? Check check. No conflicts? Ship it already."),
    ListItem(
        "Keep work moving. Review or merge code, manage notifications, browse repositories, and more with GitHub for mobile."),
    ListItem(
        "Work however you want. Put a GUI on it with GitHub Desktop or stay in the command line with GitHub CLI."),
    ListItem("Blazing fast cloud developer environments with Codespaces"),
    ListItem("Learn more about Github Actions", isHeader: true),
    ListItem(
        "Setup CI/CD, enhance your DevOps, and script your entire workflow with GitHub Actions. Kick off automated workflows with GitHub events like push, issue creation, merge, and release."),
    ListItem(
        "Write your own, or import Actions from the open source community, all within our world-class editor. Feeling stuck? Browse the Actions developer docs as you code."),
    ListItem(
        "You can have it all. Run actions in any language or operating system, on Linux, macOS, Windows, ARM, and containers. Or all at once with matrix builds.")
  ];

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("条目事件-FlatButton"),
      ),
      body: Container(
          padding: EdgeInsets.all(16), child: ListViewDemoHome(list, _style)),
    );
  }
}

class ListViewDemoHome extends StatefulWidget {
  final BuildStyle style;
  final List<ListItem> datas;

  const ListViewDemoHome(this.datas, this.style, {Key? key}) : super(key: key);

  @override
  _ListViewDemoHomeState createState() => _ListViewDemoHomeState();
}

class _ListViewDemoHomeState extends State<ListViewDemoHome> {
  Widget buildListTile(ListItem e, int index) {
    print("index:$index");
    return FlatButton(
      onPressed: () {
        Navigator.of(context).push(MaterialPageRoute(
            builder: (context) => DetailListItemTest(e.text)));
      },
      child: Column(
        children: [
          ListTile(
            title: e.isHeader
                ? Text(
                    e.text,
                    style:
                        TextStyle(fontSize: 24.0, fontWeight: FontWeight.bold),
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                  )
                : Text(e.text),
          ),
          SizedBox(
            height: 5,
          ),
          index == widget.datas.length - 1
              ? Container()
              : Divider(
                  color: Colors.blueGrey,
                )
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: ListView(
        children: List.generate(widget.datas.length,
            (index) => buildListTile(widget.datas[index], index)),
      ),
    );
  }
}
